package com.sp2.dev.dao.system;

import com.sp2.dev.bean.system.CostTime;
import com.sp2.dev.jdbc.exception.BaseDao;
import com.sp2.dev.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by IntelliJ IDEA.
 * User: zhimingli
 * Date: 14-1-26
 * Time: 上午10:10
 * To change this template use File | Settings | File Templates.
 
  CREATE TABLE `test_cost_time` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `url` varchar(225) DEFAULT NULL,
  `costtime` double DEFAULT NULL,
  `requestmethod` varchar(225) DEFAULT NULL,
  `createtime` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf-8
 */
public class CostTimeDao extends BaseDao {
    private static Logger logger = LoggerFactory.getLogger(CostTimeDao.class);

    private static String tableName = "test_cost_time";
    private static BaseDao baseDao = new BaseDao();

    public void insert(CostTime costTime) {
        String sql = null;
        Statement stmt = null;
        if (costTime != null) {
            sql = "insert " + tableName + "(url,costtime,requestmethod,createtime) value('" + costTime.getUrl() + "'," + costTime.getCosttime() +  ",'"+costTime.getRequestmethod()+"','"+ DateUtil.convert2String(System.currentTimeMillis(), DateUtil.TIME_FORMAT)+"')";
        }
        Connection conn = baseDao.conn.getConnection();
        try {
            stmt = conn.createStatement();
            stmt.executeUpdate(sql);
        } catch (SQLException e) {
            e.printStackTrace();
            logger.error("CostTimeDao insert function ====== "+e);
        }
    }
}
